home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 February / CMCD0205.ISO / Software / Freeware / Programare / bluej / bluejsetup-203.exe / {app} / examples / people2 / Database.java < prev    next >
Text File  |  2004-12-19  |  853b  |  44 lines

  1. import java.util.ArrayList;
  2. import java.util.Iterator;
  3.  
  4. /**
  5.  * A very simple database of people in a university. This class simply stores
  6.  * persons and, at request, lists them on standard output.
  7.  *
  8.  * Written as a first demo program for BlueJ.
  9.  *
  10.  * @author  Michael Kolling
  11.  * @version 1.1, March 2002
  12.  */
  13.  
  14. public class Database {
  15.  
  16.     private ArrayList persons;
  17.  
  18.      /**
  19.      * Create a new, empty person database.
  20.      */
  21.       public Database() 
  22.     {
  23.         persons = new ArrayList();
  24.     }
  25.  
  26.     /**
  27.      * Add a person to the database.
  28.      */
  29.     public void addPerson(Person p) 
  30.     {
  31.         persons.add(p);
  32.     }
  33.  
  34.     /**
  35.      * List all the persons currently in the database on standard out.
  36.      */
  37.     public void listAll () 
  38.     {
  39.         for (Iterator i = persons.iterator(); i.hasNext();) {
  40.             System.out.println(i.next());
  41.         }
  42.     }
  43. }
  44.